package br.com.sge.servicosimp;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.Transaction;

import br.com.sge.entidades.Disciplina;
import br.com.sge.entidades.Professor;
import br.com.sge.servicos.ProfessorServico;
import br.com.sge.util.HibernateUtil;

/**
 *
 *@author Gustavo Rodrigues Torre
 */
public class ProfessorServicoImp implements ProfessorServico {

    public void save(Professor professor) {
        Session session = HibernateUtil.getSessionFactory().openSession();
        Transaction t = session.beginTransaction();
        session.save(professor);
        t.commit();
    }
    public Professor getProfessor(long id) {
        Session session = HibernateUtil.getSessionFactory().openSession();
        return (Professor) session.load(Professor.class, id);
    }
    
    public Disciplina getDisciplina(long id) {
    	 Session session = HibernateUtil.getSessionFactory().openSession();
         return (Disciplina) session.load(Disciplina.class, id);
    }
    
    public List<Professor> list() {
        Session session = HibernateUtil.getSessionFactory().openSession();
        Transaction t = session.beginTransaction();
        List lista = session.createQuery("from Professor").list();
        t.commit();
        return lista;
    }
       
    public void remove(Professor professor) {
        Session session = HibernateUtil.getSessionFactory().openSession();
        Transaction t = session.beginTransaction();
        session.delete(professor);
        t.commit();
    }
    public void update(Professor professor) {
        Session session = HibernateUtil.getSessionFactory().openSession();
        Transaction t = session.beginTransaction();
        session.update(professor);
        t.commit();
    }
}
